-
-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an option to terminate all existing connections to the database when resetting a database #239
base: main
Are you sure you want to change the base?
Conversation
); | ||
if (force) { | ||
await pgClient.query( | ||
`DROP DATABASE IF EXISTS ${escapeIdentifier(databaseName)} WITH (FORCE);`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introduced in PG13, so this is technically supported by all supported versions of PostgreSQL now. Interesting.
Thanks for the PR... I shall search my feelings 🤔 |
Sorry for the delay... Even now, as I write this comment, I'm going back and forth on how I feel about it. It makes me feel uncomfortable... I don't really like the idea behind it. But also, it's for the I guess my main concern is that this opens up a can of worms and may result in people raising further PRs after this (e.g. "lock the DB after reset to prevent X, Y and Z", "create the database with a different name and then rename it", etc) when really they shouldn't be running their application against a DB that's being reset - and if they weren't, they wouldn't need this PR. |
Given your use case, I'd just recommend that you teach your test suite to be better at closing lingering connections (or you use A technique that works really well for PostGraphile's test suite is to create a template test DB, then each test creates a clone of this template using a random name to use for that test and drops it at the end. The best part of this is it allows all my tests to run in parallel, the only downside of which is that the fans on my PC suddenly sound like a hurricane as all 32 cores are maxed out! (Cloning a template DB, assuming it doesn't have loads of data, is generally a sub-second operation.) |
Description
This PR introduces a new
--force
option for thegraphile-migrate reset
command, which allows terminating existing connections to the database when dropping it.I often face a case during end-to-end testing when before each test case I want to reset the database. Unfortunately due to some lingering connections from previous tests, the
graphile-migrate reset
command sometimes throws an error as expected. This change allows to bypass that limitation.Performance impact
Unknown.
Security impact
Unknown.
Checklist
yarn lint:fix
passes.yarn test
passes.RELEASE_NOTES.md
file (if one exists).